package cn.itcast.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@RestController
public class UserController {
    //支持热更新
    @Value("${app.dateformat}")
    private String dateformat;

    @Value("${spring.redis.host}")
    private String redishost;

    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("/hello")
    public String hello(){

        //更改成功 但redis 数据库这种连接配置仍生效
        System.out.println(redishost);

        redisTemplate.opsForValue().set("username","zhangsan");
        Object o = redisTemplate.opsForValue().get("username");
        System.out.println(o);

        return LocalDateTime.now().format(DateTimeFormatter.ofPattern(dateformat));
    }
}
